import yaml
# 定义一个python对象
# data = {
#     'client': {"default-character-set": 'utf-8'},
#     'mysql': {'user': 'root', 'password': 123},
#     'custom': {
#         'user1': {'user': '张三', 'pwd': '666'},
#         'user2': {'user': '李四', 'pwd': 999}
#     }
# }
#
# # 将python对象转化为yaml文件
# with open('./my_yaml', 'w', encoding='utf-8') as f:
#     # 如果写入内容包含中文，allow_unicode=True
#     yaml.dump(data, f, allow_unicode=True)

# 从yaml文件中读取数据，并转化为python文件
with open('./my_yaml', 'r', encoding='utf-8') as f:
    yaml_data1 = yaml.safe_load(f)
    print(yaml_data1)

    # print(yaml_data1['custom']['user1']['user'])



